package rhc.common.util;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

public class SystemTerminateUtil {

	private static final List<Runnable> TERMINATE_ACTION=Collections.synchronizedList(new LinkedList<Runnable>());
	
	static{
		Runtime.getRuntime().addShutdownHook(new Thread("terminate-action"){
			public void run(){
				if(null == TERMINATE_ACTION || TERMINATE_ACTION.size() == 0){
					return;
				}
				for(Runnable r:TERMINATE_ACTION){
					r.run();
				}
			}
		});
	}
	
	/**����һ����jvm�ر�ʱ����ĺ���
	 * @param run
	 */
	public static void addTerminateRunnable(Runnable run){
		if(null != run){
			TERMINATE_ACTION.add(run);
		}
	}
	
	
}
